<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>

</body>
<script>
	Function.prototype.myBind = function(context){
		if (typeof context === "number" || typeof context === "string" || typeof context === "boolean") {
			context = new Object(context);
		}else if(context === undefined || context === null){
			context = window;
		}
		// const _this = this;
		// console.log(Array.from(arguments).slice(1))
		const bindArr = Array.from(arguments).slice(1);
		const propName = Math.random().toString(36).slice(2);
		context[propName] = this;
		return function(){
			// _this即是fn
			// console.log(Array.from(arguments));
			// console.log(bindArr.concat(Array.from(arguments)));// [1, 2, 3, 4, 5]
			// _this(...bindArr.concat(Array.from(arguments)));
			// eval("_this("+bindArr.concat(Array.from(arguments)).join(",")+")");
			eval("context[propName]("+bindArr.concat(Array.from(arguments)).join(",")+")");
			delete context[propName];
		}
	}
	
	function fn(a,b,c,d,e,f){
		console.log(a,b,c,d,e,f,this);// 1 2 3 4 5 undefined {a:1}
	}
	// fn.myBind({a:1},1,2,3)(4,5);
	fn.myBind(undefined,1,2,3)(4,5,6);
</script>
</html>